﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System.IO;

namespace LoginServer
{
    [Serializable]
    [XmlRoot]
    public class CONFIG
    {
        [XmlElement]
        public string IPSERVER { get; set; }
        [XmlElement]
        public int PORTSERVER { get; set; }
        [XmlElement]
        public int MAX_USER_CONNECTION { get; set; }
        [XmlElement]
        public int MACHINE_COUNT { get; set; }

        private ObservableCollection<MACHINE> machines = new ObservableCollection<MACHINE>();

        [XmlArrayItem("MACHINE")]
        public ObservableCollection<MACHINE> MACHINES
        {
            get
            {
                if (machines != null)
                    return machines;
                return null;
            }
            set
            {
                machines= value;
            }
        }

        public static CONFIG Load(string path)
        {
            CONFIG obj = null;
            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(CONFIG));
                StreamReader rd = new StreamReader(path);
                obj = xml.Deserialize(rd) as CONFIG;
                rd.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return obj;
        }
        
    }
    [Serializable]
    public class MACHINE
    {
        [XmlAttribute]
        public byte ID { get; set; }
        [XmlAttribute]
        public string IP_MACHINE { get; set; }
        [XmlAttribute]
        public int PORT_SERVER { get; set; }
    }
    
}
